home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Culturalia.ifs < prev    next >
Encoding:
Text File  |  2004-10-01  |  13.0 KB  |  399 lines

  1. // GETINFO SCRIPTING
  2. // Culturalia  (Con Portada)
  3.  
  4. (***************************************************
  5.  *  Movie importation script for:                  *
  6.  *    Culturalia, http://www.culturalianet.com     *
  7.  *                                                 *
  8.  *  Original version made by David Arenillas       *
  9.  *  New version made by Antoine Potten             *
  10.  *  Contributors:                                  *
  11.  *    Jose Miguel Folgueira                        *
  12.  *    RedDwarf                                     *
  13.  *    Hades666                                     *
  14.  *    KaBeCi                                       *
  15.  *    PolloPolea                                   *
  16.  *                                                 *
  17.  *  Sort Results Made by Moises DΘniz 13/04/2004   *
  18.  *                                                 *
  19.  *  TransformTitle function from IMDB (US) Script  *
  20.  *  (c) 2002-2004 Antoine Potten                   *
  21.  *                          software@antp.be       *
  22.  *  Contributors :                                 *
  23.  *    Danny Falkov                                 *
  24.  *    Kai Blankenhorn                              *
  25.  *    lboregard                                    *
  26.  *    Ork <ork@everydayangels.net>                 *
  27.  *    Trekkie <Asimov@hotmail.com>                 *
  28.  *                                                 *
  29.  *  Thanks to Culturalia's webmaster for his help  *
  30.  *  and for providing more direct access to his    *
  31.  *  database                                       *
  32.  *                                                 *
  33.  *  For use with Ant Movie Catalog 3.4.x           *
  34.  *  www.antp.be/software/moviecatalog              *
  35.  *                                                 *
  36.  *  This program is free software; you can         *
  37.  *  redistribute it and/or modify it under the     *
  38.  *  terms of the GNU General Public License as     *
  39.  *  published by the Free Software Foundation;     *
  40.  *  either version 2 of the License, or (at your   *
  41.  *  option) any later version.                     *
  42.  ***************************************************)
  43.  
  44. program Culturalia;
  45. const
  46.   BaseURL = 'http://www.culturalianet.com/bus/catalogo.php';
  47.  
  48.   TitleMixedCase = False; // If true, each letter of each word of title begins with Uppercase. If false, the script transforms the titles in lowercase except first word
  49.   ExternalPictures = False;
  50.      { True: Pictures will be stored as external files in the folder of the catalog
  51.        False: Pictures will be stored inside the catalog (only for .amc files) }
  52.   // Donde vamos a buscar en el caso de no haber introducido ni el tφtulo original ni el traducido en los campos correspondientes, sino en la ventana que
  53.   // se abre y nos lo solicita.
  54.   // 1-Titulo traducido, 2-Titulo original, 3-General
  55.   // What type of search in case we don't write the original title nor traslated one in the corresponding fields, we do it in the input box.
  56.   // 1-Translated title, 2-Original Title, 3-General
  57.   defdonde='1';
  58.  
  59. var
  60.   MovieName: string;
  61.   tmp: string;
  62.   donde: string; 
  63.   Articles: array of string;
  64.   Index: Integer;
  65.  
  66. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  67. var
  68. i: Integer;
  69. begin
  70. result := -1;
  71. if StartAt < 0 then
  72.   StartAt := 0;
  73. for i := StartAt to List.Count-1 do
  74.   if Pos(Pattern, List.GetString(i)) <> 0 then
  75.   begin
  76.    result := i;
  77.    Break;
  78.   end;
  79. end;
  80.  
  81. function TransformTitle(Title: string): string;
  82. var
  83.   BeginPos, EndPos: Integer;
  84.   Value: string;
  85.   Words: array of string;
  86.   Articles: array of string;
  87.   Replace,Original: string;
  88.   Index, CommaCount: Integer;
  89. Begin
  90.   // Original Title
  91.   Result:=Title;
  92.  
  93.   Setarraylength(Words,11);
  94.   Words[0]:=' In ';
  95.   Words[1]:=' On ';
  96.   Words[2]:=' Of ';
  97.   Words[3]:=' As ';
  98.   Words[4]:=' The ';
  99.   Words[5]:=' At ';
  100.   Words[6]:=' And A ';
  101.   Words[7]:=' And ';
  102.   Words[8]:=' An ';
  103.   Words[9]:=' To ';
  104.   Words[10]:=' For ';
  105.  
  106.   SetArrayLength(Articles,35);
  107.   Articles[0]:=' The';
  108.   Articles[1]:=' a';
  109.   Articles[2]:=' An';
  110.   Articles[3]:=' Le';
  111.   Articles[4]:=' L''';
  112.   Articles[5]:=' Les';
  113.   Articles[6]:=' Der';
  114.   Articles[7]:=' Das';
  115.   Articles[8]:=' Die';
  116.   Articles[9]:=' Des';
  117.   Articles[10]:=' Dem';
  118.   Articles[11]:=' Den';
  119.   Articles[12]:=' Ein';
  120.   Articles[13]:=' Eine';
  121.   Articles[14]:=' Einen';
  122.   Articles[15]:=' Einer';
  123.   Articles[16]:=' Eines';
  124.   Articles[17]:=' Einem';
  125.   Articles[18]:=' Il';
  126.   Articles[19]:=' Lo';
  127.   Articles[20]:=' La';
  128.   Articles[21]:=' I';
  129.   Articles[22]:=' Gli';
  130.   Articles[23]:=' Le';
  131.   Articles[24]:=' Uno';
  132.   Articles[25]:=' Una';
  133.   Articles[26]:=' Un''';
  134.   Articles[27]:=' O';
  135.   Articles[28]:=' Os';
  136.   Articles[29]:=' As';
  137.   Articles[30]:=' El';
  138.   Articles[31]:=' Los';
  139.   Articles[32]:=' Las';
  140.   Articles[33]:=' Unos';
  141.   Articles[34]:=' Unas';
  142.  
  143.   // Count the Comma in The Title
  144.   CommaCount := 0;
  145.   EndPos := 0;
  146.   Value := Title;
  147.   repeat
  148.      BeginPos := Pos(',', Value);
  149.      if BeginPos > 0 then
  150.      begin
  151.        Delete(Value, 1, BeginPos);
  152.        CommaCount := CommaCount + 1;
  153.        EndPos := EndPos + BeginPos;
  154.      end;
  155.   until( Pos(',',Value) = 0);
  156.  
  157.   // Compare the Article to a list of known ones
  158.   for Index := 0 to 34 do
  159.   begin
  160.     if Pos(Articles[Index], Value) <> 0 then
  161.     begin
  162.        CommaCount := 1;
  163.        BeginPos := EndPos;
  164.        Break;
  165.     end;
  166.   end;
  167.  
  168.   if (BeginPos > 0) and (CommaCount = 1) then
  169.   begin
  170.     Value := Copy(Title, BeginPos + 1, Length(Title));
  171.     Value := Trim(Value);
  172.     Result := Value + ' ' + Copy(Title, 1, BeginPos - 1);
  173.   end;
  174.  
  175.   BeginPos := Pos(': ', Result);
  176.   if BeginPos > 0 then
  177.     Result := StringReplace(Result, ': ', ' - ');
  178.  
  179.   If TitleMixedCase then
  180.      Result := AnsiMixedCase(Result, ' ')
  181.   else
  182.     begin
  183.      Result := AnsiLowerCase(Result);
  184.      Result := AnsiUpFirstLetter(Result);
  185.     end;
  186.  
  187.   for Index := 0 to 10 do
  188.   begin
  189.     if Pos(Words[Index],Result) <> 0 then
  190.     begin
  191.       Original := Words[Index];
  192.       Replace := AnsiLowerCase(Original);
  193.       Result := StringReplace(Result, Original, Replace);
  194.     end;
  195.   end;
  196.  
  197.   Result := StringReplace(Result, ' - the ', ' - The ');
  198.   Result := Trim(Result);
  199. end;
  200.  
  201. function Valoracion(Resultado: string; Titulo :TStringList) : Integer;
  202. var i,j,val: integer;
  203. begin
  204.     val := 0;
  205.     for i := 0 to Titulo.Count-1 do
  206.       begin
  207.         if (Pos(Titulo.GetString(i),Resultado) > 0) then
  208.           val := val + 5;
  209.       end;
  210.     Valoracion := val;
  211. end;
  212.  
  213. procedure SortStrings(var List : TStringList; Nombre : string);
  214. var i,j,ValI,ValJ: integer;
  215.     NombreArray: TStringList;
  216.     palabra : string;
  217. begin
  218.     Nombre := LowerCase(Nombre);
  219.     NombreArray := TStringList.Create;
  220.     while ((pos(' ',Nombre) > 0) and (Length(Nombre)> 0)) do
  221.     begin
  222.       palabra := copy(Nombre,0,pos(' ',Nombre)-1);
  223.       Nombre  := copy(Nombre,pos(' ',Nombre)+1,Length(Nombre));
  224.       NombreArray.Add(palabra);
  225.     end
  226.     NombreArray.Add(Nombre);
  227.     for i := 0 to List.Count-1 do
  228.     begin
  229.       for j := 0 to List.Count-1 do
  230.       begin
  231.          ValI := Valoracion(LowerCase(List.GetString(i)),NombreArray);
  232.          ValJ := Valoracion(LowerCase(List.GetString(j)),NombreArray);
  233.          if (ValI > ValJ) then
  234.           begin
  235.           List.Exchange(i,j);
  236.           end;
  237.          if (ValI = ValJ) and (List.GetString(i) < List.GetString(j)) then
  238.           List.Exchange(i,j);
  239.       end;
  240.     end;
  241.     NombreArray.Free;
  242. end;
  243.  
  244. procedure AnalyzePage(Address,Nombre: string);
  245. var
  246.   Page,TempTit: TStringList;
  247.   LineNr,i: Integer;
  248.   Code, Title, TitleOrig, Year,Texto,Url: string;
  249. begin
  250.   Page := TStringList.Create;
  251.   TempTit := TStringList.Create;
  252.   Page.Text := GetPage(Address);
  253.   if Pos('No se ha encontrado ning·n artφculo por tφtulo', Page.Text) > 0 then
  254.   begin
  255.     ShowMessage('No se ha encontrado ninguna coincidencia por tφtulo');
  256.   end else
  257.   begin
  258.     PickTreeClear;
  259.     LineNr := 1;
  260.     Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  261.     while LineNr + 3 < Page.Count do
  262.     begin
  263.       Code := GetValueAfter(Page.GetString(LineNr), 'Codigo = ');
  264.       Title := GetValueAfter(Page.GetString(LineNr+1), 'Titulo = ');
  265.       TitleOrig := GetValueAfter(Page.GetString(LineNr+2), 'Titulo original = ');
  266.       Year := GetValueAfter(Page.GetString(LineNr+3), 'A±o = ');
  267.       TempTit.Add(Title + ' (' + TitleOrig + '), ' + Year+';'+BaseURL + '?catalogo=1&codigo=' + Code);
  268.       LineNr := LineNr + 5;
  269.     end;
  270.     SortStrings(TempTit,Nombre);
  271.     PickTreeAdd('Resultados mßs probables de buscar: "'+Nombre+'"', '');
  272.     for i := 0 to TempTit.Count-1 do
  273.         begin
  274.          Texto := copy(TempTit.GetString(i),0,Pos(';',TempTit.GetString(i))-1);
  275.          Url := copy(TempTit.GetString(i),Pos(';',TempTit.GetString(i)),Length(TempTit.GetString(i)));
  276.          PickTreeAdd(Texto,Url);
  277.          if (i = 0) then PickTreeAdd('Resto de resultados de buscar: "'+Nombre+'"', '');
  278.         end;
  279.     Page.Free;
  280.     TempTit.Free;
  281.     if PickTreeExec(Address) then
  282.       AnalyzeMoviePage(Address);
  283.   end;
  284. end;
  285.  
  286. procedure AnalyzeMoviePage(Address: string);
  287. var
  288.   Page: TStringList;
  289.   Comments: string;
  290.   strTitle: string;
  291.   strSinopsis: string;
  292.   Line: string;
  293.   LineNr: Integer;
  294.   tmp: string;
  295.  
  296.  
  297. begin
  298.   Page := TStringList.Create;
  299.   Page.Text := StringReplace(GetPage(Address), '<br><br>', #13#10);
  300.   Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  301.   strTitle := GetValueAfter(Page.GetString(1), 'Titulo = ');
  302.   if copy(strTitle, Length(strTitle), Length(strTitle)) = '.' then
  303.   begin
  304.     tmp := Copy(strTitle, 1, Length(strTitle) -1);
  305.   end else
  306.   begin
  307.     tmp := strTitle;
  308.   end;
  309.   SetField(fieldTranslatedTitle, TransformTitle(tmp));
  310.   tmp := GetValueAfter(Page.GetString(2), 'Titulo original = ');
  311.   SetField(fieldOriginalTitle, TransformTitle(tmp));
  312.   SetField(fieldYear, GetValueAfter(Page.GetString(3), 'A±o = '));
  313.   SetField(fieldCategory, GetValueAfter(Page.GetString(4), 'Genero = '));
  314.   SetField(fieldCountry, GetValueAfter(Page.GetString(5), 'Nacion = '));
  315.   SetField(fieldDirector, GetValueAfter(Page.GetString(6), 'Director = '));
  316.   SetField(fieldActors, GetValueAfter(Page.GetString(7), 'Actores = '));
  317.   SetField(fieldProducer, GetValueAfter(Page.GetString(8), 'Productor = '));
  318.   Comments := 'Gui≤n: ' + GetValueAfter(Page.GetString(9), 'Guion = ');
  319.   Comments := Comments + #13#10 + 'Fotografφa: ' + GetValueAfter(Page.GetString(10), 'Fotografia = ');
  320.   Comments := Comments + #13#10 + 'M·sica: ' + GetValueAfter(Page.GetString(11), 'Musica = ');
  321.   SetField(fieldComments, Comments);
  322.   LineNr := FindLine('Sinopsis = ', Page, 0);
  323.   Line := Page.GetString(LineNr);
  324.   strSinopsis := GetValueAfter(Line, 'Sinopsis = ');
  325.   LineNr := LineNr + 1;
  326.   Line := Page.GetString(LineNr);
  327.   while pos('URL = ', Line) = 0 do
  328.   begin
  329.     strSinopsis := strSinopsis + #13#10 + Line;
  330.     LineNr := LineNr + 1;
  331.     Line := Page.GetString(LineNr);
  332.   end
  333.   HTMLRemoveTags(strSinopsis);
  334.   SetField(fieldDescription, StringReplace(StringReplace(strSinopsis, 'ô', '"'), 'ö', '"'));
  335.   LineNr := FindLine('URL = ', Page, 0);
  336.   if LineNr <> -1 then
  337.     SetField(fieldURL, GetValueAfter(Page.GetString(LineNr), 'URL = '));
  338.   LineNr := FindLine('Imagen = ', Page, 0);
  339.   if LineNr <> -1 then
  340.     GetPicture(GetValueAfter(Page.GetString(LineNr), 'Imagen = '), ExternalPictures);
  341.   Page.Free;
  342.   DisplayResults;
  343. end;
  344.  
  345. function GetValueAfter(Line, Identifier: string): string;
  346. begin
  347.   if Pos(Identifier, Line) = 1 then
  348.     Result := Copy(Line, Length(Identifier)+1, Length(Line))
  349.   else
  350.     Result := '';
  351. end;
  352.  
  353. begin
  354.   SetArrayLength(Articles,11);
  355.   Articles[0]:='Lo ';
  356.   Articles[1]:='La ';
  357.   Articles[2]:='Le ';
  358.   Articles[3]:='Uno ';
  359.   Articles[4]:='Una ';
  360.   Articles[5]:='Un ';
  361.   Articles[6]:='El ';
  362.   Articles[7]:='Los ';
  363.   Articles[8]:='Las ';
  364.   Articles[9]:='Unos ';
  365.   Articles[10]:='Unas ';
  366.  
  367.   if CheckVersion(3,4,0) then
  368.    begin
  369.      MovieName := GetField(fieldOriginalTitle);
  370.      donde := '&donde=2';
  371.      if MovieName = '' then
  372.       begin
  373.        MovieName := GetField (fieldTranslatedTitle);
  374.        donde := '&donde=1';
  375.       end
  376.      if MovieName = '' then
  377.       begin
  378.        Input('Importar de Culturalia', 'Introduce el Titulo de la Pelicula:', MovieName);
  379.        donde := '&donde=' + defdonde;
  380.       end
  381.      if MovieName <> '' then
  382.        begin
  383.         // Eliminate spanish article if exists
  384.         for Index := 0 to 10 do
  385.         begin
  386.          if Pos(Articles[Index], MovieName) <> 0 then
  387.          MovieName := copy(MovieName, length(Articles[Index]), length(MovieName));
  388.         end;
  389.  
  390.          // Eliminate point(s) at final of MovieName before search
  391.          tmp := MovieName;
  392.          if Copy(tmp, Length(tmp), Length(tmp)) = '.' then
  393.             MovieName := Copy(tmp, 1, Length(tmp) -1);
  394.          AnalyzePage(BaseURL + '?catalogo=1&texto=' + UrlEncode(MovieName) + donde, MovieName);
  395.        end;
  396.    end else
  397.      ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
  398. end.
  399.